//
//  HLNavagationController.m
//  HLMusicBox
//
//  Created by hulinhu on 2017/12/26.
//  Copyright © 2017年 hulinhu. All rights reserved.
//

#import "HLNavagationController.h"

@interface HLNavagationController ()<UIGestureRecognizerDelegate,UINavigationControllerDelegate>

@end

@implementation HLNavagationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self configNavgationBarSetting];

    // 手势滑动返回上一层功能
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.delegate = self;
        self.delegate = self;
    }
}

-(void)configNavgationBarSetting{
    
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    
    return (self.viewControllers.count > 1);
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
    NSLog(@"vc class = %@",NSStringFromClass([viewController class]));
    // 禁用手势滑动返回上一层功能
    if (self.childViewControllers.count == 1) {
        viewController.hidesBottomBarWhenPushed = YES; //viewController是将要被push的控制器
    }

    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.enabled = NO;
    }
    
    [super pushViewController:viewController animated:animated];

}


- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.enabled = YES;
    }
    
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{

}


@end
